/**
 * DelRoleController.java
 */
package org.yate.oa.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.math.NumberUtils;
import org.yate.oa.service.IRoleService;

import com.alibaba.fastjson.JSONObject;

/**
 * @author Yate
 * @date Nov 19, 2013
 * @description TODO
 * @version 1.0
 */
@WebServlet(urlPatterns = { "/role/delete" }, asyncSupported = true)
public class DelRoleController extends BaseServletController {

	private IRoleService roleService;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.yate.oa.controller.BaseController#init(javax.servlet.ServletConfig
	 * )
	 */
	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		this.roleService = (IRoleService) this.springCtx.getBean("roleService");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest
	 * , javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		PrintWriter out = resp.getWriter();
		JSONObject json = new JSONObject();
		long rid = NumberUtils.toLong(req.getParameter("rid"), -1);
		if (rid == -1) {
			json.put("code", "401");
			json.put("msg", "paramater rid error");
			out.println(json);
			out.flush();
			out.close();
			return;
		}
		
		this.roleService.remove(rid);

		json.put("code", "200");
		json.put("msg", "ok");
		out.println(json);
		out.flush();
		out.close();
		return;
	}

}
